package com.ocom.webapi.controller;

import com.ocom.common.constant.XFPayUrl;
import com.ocom.common.resp.Result;
import com.ocom.security.authentication.YoCiUser;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.service.AccountTypePageService;
import com.ocom.webapi.vo.accounttypepage.AddVo;
import com.ocom.webapi.vo.accounttypepage.ModifyVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class AccountTypePageController {

    @Autowired
    private AccountTypePageService accountTypePageService;

    // 获取账号类型（AccountTypePage/onShow）
    @GetMapping(XFPayUrl.URL_AccountTypePageOnShow)
    public Result AccountTypePageOnShow(Long comId){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        log.info("获取账号类型请求参数：{{}}{{}}",comId,yoCiUser);
        return accountTypePageService.AccountTypePageOnShow(yoCiUser.getComId());
    }

    // 新增账号类型（AccountTypePage/add）
    @PostMapping(XFPayUrl.URL_AccountTypePageAdd)
    public Result AccountTypePageAdd(@Validated @RequestBody AddVo addVo){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        addVo.setComId(yoCiUser.getComId());
        log.info("新增账号类型请求参数:{{}}",addVo);
        return accountTypePageService.AccountTypePageAdd(addVo);
    }

    // 修改账号类型（AccountTypePage/modify）
    @PostMapping(XFPayUrl.URL_AccountTypePageModify)
    public Result AccountTypePageModify(@Validated @RequestBody ModifyVo modifyVo){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        modifyVo.setComId(yoCiUser.getComId());
        log.info("修改账号类型请求参数:{{}}",modifyVo);
        return accountTypePageService.AccountTypePageModify(modifyVo);
    }


}
